package com.jinmdz.fmis.mapper.mapper.provider;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;
import com.jinmdz.fmis.mapper.entity.FaceLiftItemEntity;

/**
 * 整容项目表Provider
 * 
 * @author generator
 * @date 2020-08-23 18:11
 */
public class FaceLiftItemProvider {

    /**
     * 增加FaceLiftItem
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String insertFaceLiftItem(@Param("entity") FaceLiftItemEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" face_lift_item ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" business_code ", " #{entity.businessCode,jdbcType=VARCHAR} ");
                VALUES(" service_item_id ", " #{entity.serviceItemId,jdbcType=INTEGER} ");
                VALUES(" require_finish_time ", " #{entity.requireFinishTime,jdbcType=TIMESTAMP} ");
                VALUES(" reality_finish_time ", " #{entity.realityFinishTime,jdbcType=TIMESTAMP} ");
                VALUES(" finish_user_id ", " #{entity.finishUserId,jdbcType=INTEGER} ");
                VALUES(" process_state_code ", " #{entity.processStateCode,jdbcType=TINYINT} ");
                VALUES(" random_code ", " #{entity.randomCode,jdbcType=VARCHAR} ");
                VALUES(" charge_id ", " #{entity.chargeId,jdbcType=INTEGER} ");

                if (entity.getAsArrangeFlower() != null) {
                    VALUES(" as_arrange_flower ", " #{entity.asArrangeFlower,jdbcType=TINYINT} ");
                }

                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改FaceLiftItem
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String updateFaceLiftItem(@Param("entity") FaceLiftItemEntity entity) {
        return new SQL() {
            {
                UPDATE(" face_lift_item ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" business_code = #{entity.businessCode,jdbcType=VARCHAR} ");
                SET(" service_item_id = #{entity.serviceItemId,jdbcType=INTEGER} ");
                SET(" require_finish_time = #{entity.requireFinishTime,jdbcType=TIMESTAMP} ");
                SET(" reality_finish_time = #{entity.realityFinishTime,jdbcType=TIMESTAMP} ");
                SET(" finish_user_id = #{entity.finishUserId,jdbcType=INTEGER} ");
                SET(" process_state_code = #{entity.processStateCode,jdbcType=TINYINT} ");
                SET(" random_code = #{entity.randomCode,jdbcType=VARCHAR} ");
                SET(" charge_id = #{entity.chargeId,jdbcType=INTEGER} ");

                if (entity.getAsArrangeFlower() != null) {
                    SET(" as_arrange_flower = #{entity.asArrangeFlower,jdbcType=TINYINT} ");
                }

                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询FaceLiftItem列表
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String listFaceLiftItem(@Param("entity") FaceLiftItemEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,business_code,service_item_id,require_finish_time,reality_finish_time,finish_user_id,process_state_code,random_code,charge_id,as_arrange_flower,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" face_lift_item ");

                if (entity.getBusinessCode() != null) {
                    WHERE(" business_code = #{entity.businessCode,jdbcType=VARCHAR} ");
                }

                if (entity.getServiceItemId() != null) {
                    WHERE(" service_item_id = #{entity.serviceItemId,jdbcType=INTEGER} ");
                }

                if (entity.getRequireFinishTime() != null) {
                    WHERE(" require_finish_time = #{entity.requireFinishTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getRealityFinishTime() != null) {
                    WHERE(" reality_finish_time = #{entity.realityFinishTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getFinishUserId() != null) {
                    WHERE(" finish_user_id = #{entity.finishUserId,jdbcType=INTEGER} ");
                }

                if (entity.getProcessStateCode() != null) {
                    WHERE(" process_state_code = #{entity.processStateCode,jdbcType=TINYINT} ");
                }

                if (entity.getRandomCode() != null) {
                    WHERE(" random_code = #{entity.randomCode,jdbcType=VARCHAR} ");
                }

                if (entity.getChargeId() != null) {
                    WHERE(" charge_id = #{entity.chargeId,jdbcType=INTEGER} ");
                }

                if (entity.getAsArrangeFlower() != null) {
                    WHERE(" as_arrange_flower = #{entity.asArrangeFlower,jdbcType=TINYINT} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}